#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, m, L, V;
int d[N], v[N], a[N];
int p[N];
bool check(int x, int id) {
    if(d[id] > p[x]) {
        return 0;
    }
    int tmp = v[id] * v[id] + 2 * a[id] * (p[x] - d[id]);
    if(tmp > V * V) {
        return 1;
    }
    return 0;
}
signed main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while(t--) {
        bool f1 = 0, f2 = 0, f3 = 0;
        cin >> n >> m >> L >> V;
        for(int i = 1; i <= n; i++) {
            cin >> d[i] >> v[i] >> a[i];
            if(a[i] != 0)
                f1 = 1;
            if(a[i] <= 0)
                f2 = 1;
            if(a[i] >= 0) 
                f3 = 1;
        }
        int mx = -1;
        for(int i = 1; i <= m; i++) {
            cin >> p[i];
            mx = max(p[i], mx);
        }
        sort(p + 1, p + 1 + m);
        if(f1 == 0) {
            int sum = 0;
            for(int i = 1; i <= n; i++) {
                if(v[i] > V && d[i] <= mx) {
                    sum++;
                }
            }
            if(sum == 0) {
                cout << 0 << ' ' << m << '\n';
            } else {
                cout << sum << ' ' << m - 1 << '\n';
            }
        } else if(f2 == 0) {
            int sum = 0;
            for(int i = 1; i <= n; i++) {
                if(check(m, i)) {
                    sum ++;
                }
            }
            if(sum != 0) {
                cout << sum << ' ' << m - 1 << '\n';
            } else {
                cout << 0 << ' ' << m << '\n';
            }
        } else if(f3 == 0) {
            int vis[N];
            memset(vis, 0, sizeof(vis));
            int sum = 0, mxx = 0;
            for(int i = 1; i <= n; i++) {
                int st = -1, ed = m;
                for(int j = 1; j <= m; j++) {
                    if(st == -1 && check(j, i)) {
                        st = j;
                    }
                    if(ed == m && !check(j, i) && st != -1) {
                        ed = j;
                    }
                }
                if(st != -1) {
                    sum++;
                } else {
                    continue;
                }
                // cout << st << ' ' << ed << '\n';
                for(int j = st; j <= ed - 1; j++) {
                    vis[j] ++;
                }
            }
            int xxx = 0, ttt = 0;
            for(int i = 1; i <= m; i++) {
                if(vis[i] == 0) {
                    xxx += mxx;
                    mxx = 0;
                    ttt = 0;
                } else {
                    ttt ++;
                    mx = max(vis[i], mx);
                }
            }
            xxx += mxx;
            cout << sum << ' ' << m - xxx << '\n';
        }
    }
    return 0;
}
